package io.seata.samples.tcc.springboot.dubbo.controller;

import io.seata.samples.tcc.springboot.dubbo.service.TccTransactionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 发起事务控制器
 *
 * @author louis
 */
@RestController
public class TccController {

    @Resource
    private TccTransactionService tccTransactionService;

    /**
     * 分布式事务提交示例接口
     */
    @GetMapping("/testCommit")
    public String testCommit() {
        String xid = tccTransactionService.testCommit();
        return "transaction commit, xid=" + xid;
    }

    /**
     * 分布式事务回滚示例接口
     */
    @GetMapping("/testRollback")
    public String testRollback() {
        String msg = "";
        try {
            tccTransactionService.testRollback();
        } catch (Throwable t) {
            msg = t.getMessage();
        }
        return msg;
    }

}
